local skill = fk.CreateSkill {
  name = "#lvshi__blade_skill",
  attached_equip = "lvshi__blade",
}

local DIY = require "packages/diy_utility/diy_utility"
local TT = require "packages/tuntian_studio/utility"

skill:addEffect(fk.TargetSpecified, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skill.name) and data.card.trueName == "slash" and not data.to:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if data.to:isKongcheng() then return end
    local id = room:askToChooseCard(player, { target = data.to, flag = "h", skill_name = skill.name })
    DIY.showCards(data.to, id)
    local shown = table.filter(data.to:getCardIds("h"), function (id)
      return TT.isShown(id) and Fk:getCardById(id).color == data.card.color end)
    if #shown > 0 then
      local cid = room:askToChooseCard(player, {
        target = data.to,
        flag = { card_data = {{skill.name, shown}} },
        skill_name = skill.name })
      if cid then
        room:throwCard({cid}, skill.name, data.to, player)
      end
    end
  end,
})

return skill
